<template>
	<view class="combobox-panel" v-if="visbole" @click="clickComboboxPanel">
		<scroll-view class="combobox-scroll" @click.stop="clickNull" scroll-y>
			<view class="list">
				<view v-for="(item, index) in list" 
					:key="index"
					:class="{'list-item': true, select: item.value == value }" 
					hover-class="hover"
					@click="checkComboboxItem(item)">
					<text class="text">{{ item.title }}</text>
					<text class="arrow iconfont icon-forward"></text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			visbole: false,
			value:'',
			list:[],
			fail:function(){},
			success:function(){},
			complete:function(){},
		};
	},
	methods: {
		show: function(param = {}) {
			this.visbole = true;
			this.list = param.list??[]
			this.value = param.value??[]
			
			this.fail = param.fail??function(){}
			this.success = param.success??function(){}
			this.complete = param.complete??function(){}
		},
		hide: function(param = {}) {
			this.visbole = false;
		},
		runSuccess: function(param = {}) {
			if (this.success(param) == false) return;
			this.hide();
			this.complete(param)
		},
		runFail: function(param = {}) {
			if (this.fail(param) == false) return;
			this.hide();
			this.complete(param)
		},
		clickNull: function() {},
		clickComboboxPanel: function() {
			this.runFail({ click: 'panel' });
		},
		checkComboboxItem: function(item) {
			this.runSuccess({click: 'item', item});
		}
	}
};
</script>

<style lang="scss" scoped>
.combobox-panel {
	transition-duration: 0s;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.3);
	.combobox-scroll {
		position: absolute;
		background: var(--app-panel-bg-color);
		color: var(--app-panel-text-color);
		left: 0;
		right: 0;
		bottom: 0;
		height: 50vh;
		overflow: hidden;
		.list {
			padding: 30rpx;
			.list-item {
				line-height: 100rpx;
				align-content: center;
				display: flex;
				align-items: center;
				justify-content: center;
				white-space: nowrap;
				.text {
					font-size: 28rpx;
				}
				.arrow {
					font-size: 20rpx;
					color: #c6c6c6;
				}
			}
			.hover {
				opacity: 0.65;
			}
			.select {
				color: #0285f0;
			}
		}
		
	}
}
</style>
